package com.umakr.demo.controller;

import com.umakr.demo.model.Banji;
import com.umakr.demo.model.Nianji;
import com.umakr.demo.model.NianjiBanji;
import com.umakr.demo.service.BanjiSerivice;
import com.umakr.demo.service.NianjiBanjiService;
import com.umakr.demo.service.NianjiService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by yangliu on 2017/8/22.
 */
@Controller
@RequestMapping("/NianjiBanjiController")
public class NianjiBanjiController {

    @Autowired
    NianjiBanjiService nianjiBanjiService;

    @Autowired
    NianjiService nianjiService;

    @Autowired
    BanjiSerivice banjiSerivice;

    @RequestMapping("/nianjiDate")
    @ResponseBody
    public List nianjiDate(){
        List<Nianji> list = nianjiService.showAll();
        return list;
    }

    @RequestMapping("/banjiDate")
    @ResponseBody
    public List banjiDate(){
        List<Banji> list = banjiSerivice.showAll();
        return list;
    }

    @RequestMapping("/showNianjiBanji")
    public  String showNianjiBanji(){
        return "StudentManage/nianjibanji";
    }

    @RequestMapping("/nianjiShowBanji")
    @ResponseBody
    public List nianjiShowBanji(Long nid){
        List<Banji> list = nianjiBanjiService.nianjiShowBanji(nid);
        return list;
    }

    @RequestMapping("/allSelectedBanji")
    @ResponseBody
    public void allSelectedBanji(Long nid, @RequestParam(value = "str[]",required = false) String[] str){
//        全部删除
        nianjiBanjiService.deleteAll(nid);
        System.out.println(nid+"    _______ "   +str[0]);
        for(int i =0;i<str.length;i++){
            NianjiBanji nianjiBanji = new NianjiBanji(nid,Long.parseLong(str[i]));
            nianjiBanjiService.addAll(nianjiBanji);
        }
    }


}
